<?php
class YWSUtils {
    public static function newGuid($include_braces = false) {
        if (function_exists('com_create_guid')) {
            if ($include_braces === true) {
                return com_create_guid();
            } else {
                return substr(com_create_guid(), 1, 36);
            }
        } else {
            mt_srand((double) microtime() * 10000);
            $charid = strtoupper(md5(uniqid(rand(), false)));

            $guid = substr($charid,  0, 8) . '-' .
                    substr($charid,  8, 4) . '-' .
                    substr($charid, 12, 4) . '-' .
                    substr($charid, 16, 4) . '-' .
                    substr($charid, 20, 12);

            if ($include_braces) {
                $guid = '{' . $guid . '}';
            }

            return $guid;
        }
    }
    
    public static function createNameSpace($controller, $action, $module = null) {
        if ($module == null) return implode ('.', array($controller, $action));
        else return implode ('.', array($module, $controller, $action));
    }
    
    public static function redirect($url) {
        echo "
            <script>
                window.location = '".$url."';
            </script>
            ";
    }
    
    public static function alert($msg) {
        echo "
            <script>
                alert('".$msg."');
            </script>
            ";
    }
}
?>